//goodsdetails.js
const app = getApp();

Page({
  data: {
    id: 1,
    num: 1,
    color: 0,
    size: 0,
    goodsShow: true,
    animationData: {},
    goodsNum: 1,
    stopGoods:true
  },
  onLoad: function () {
    wx.hideShareMenu();
  },
  goodsIndex: function (e) {
    let that = this;
    that.setData({
         id:e.detail.current+1
    })
  },
  returnShop: function () {
     wx.switchTab({
       url: '/pages/homepage/homepage'
     })
  },
  allActivities: function () {
    wx.navigateTo({
       url: '/packageA/pages/allactivities/allactivities'
    })
  },
  goodsActives: function (e) {
    let that = this;
    that.setData({
        num:e.currentTarget.dataset.id
    })
  },
  goHome: function () {
    wx.switchTab({
       url: '/pages/homepage/homepage'
    })
  },
  goBuyer: function () {
    wx.switchTab({
       url: '/pages/buyercar/buyercar'
    })
  },
  addBuyer: function () {
    let that = this;
    that.setData({
        goodsShow: false
    }, () => {
        let animation = wx.createAnimation({
            duration: 600,
            timingFunction: 'ease'
        })
         that.animation = animation 
         setTimeout(function(){
           that.fadeIn();
        },200)
    })
  },
  closeGoodsLayer: function () {
    let that = this;
    that.setData({
        goodsShow: true
    }, () => {
        let animation = wx.createAnimation({
            duration: 600,
            timingFunction: 'ease'
        })
         that.animation = animation 
         setTimeout(function(){
           that.fadeOut();
        },200)
    })
  },
  fadeIn: function () {
    let that = this;
    that.animation.translateY(0).step()
    that.setData({
      animationData: that.animation.export()
    })    
  },
  fadeOut: function () {
    let that = this;
    that.animation.translateY(826).step()
    that.setData({
      animationData: that.animation.export()
    })
  },
  goodsColor: function (e) {
    let that = this;
    that.setData({
        color:e.currentTarget.dataset.color
    })
  },
  goodsSize: function (e) {
    let that = this;
    that.setData({
        size:e.currentTarget.dataset.size
    })
  },
  reduce: function () {
    let that = this;
    let number = that.data.goodsNum;
    number--;
    if (number > 1) {
       that.setData({
          goodsNum: number,
          stopGoods:false
       })
    } else if (number == 1) {
       that.setData({
          goodsNum: number,
          stopGoods:true
       })
    }
  },
  add: function () {
    let that = this;
    let number = that.data.goodsNum;
    number++;
    that.setData({
      goodsNum: number,
      stopGoods:false
    })
  },
  // onShareAppMessage: function (rea) {
  //   let that = this;
  //   let sharedatas = {
  //     title: '',
  //     imageUrl: '',
  //     path: ''
  //   }
  //   if (rea.from == 'button') {
  //     sharedatas.title = '1';
  //   }
  //   return sharedatas
  // }
  confirmGoods: function () {
       let that = this;
    that.setData({
        goodsShow: true
    }, () => {
        let animation = wx.createAnimation({
            duration: 600,
            timingFunction: 'ease'
        })
         that.animation = animation 
         setTimeout(function(){
           that.fadeOut();
         }, 200)
        wx.showToast({
          title: '添加成功',
          icon: 'none',
          duration: 2000
        })
    })
  } 
})
